﻿using Microsoft.Xna.Framework.Graphics;
using StardewModdingAPI;
using StardewModdingAPI.Events;
using StardewValley;
using StardewValley.GameData.Objects;

namespace Testmod;

public class ModEntry : Mod
{
    public override void Entry(IModHelper helper)
    {
        // 注册事件
        helper.Events.Content.AssetRequested += OnAssetRequested;
        helper.Events.GameLoop.SaveLoaded += OnSaveLoaded; 
    }


    private void OnAssetRequested(object? sender, AssetRequestedEventArgs e)
    {
        //  添加自定义物品
        if (e.Name.IsEquivalentTo("Data/Objects"))
        {
            e.Edit(asset =>
            {
                var dict = asset.AsDictionary<string, ObjectData>();

                // susuheart：自定义宝石
                var susu = new ObjectData
                {
                    Name = "susuheart",
                    DisplayName = "susuheart",
                    Description = "苏苏的爱心",
                    Type = "Minerals",
                    Category = StardewValley.Object.GemCategory,
                    Price = 9999999,
                    Texture = "susu"
                };
                dict.Data["susuheart"] = susu;

                // susucake：自定义甜点
                var susucake = new ObjectData
                {
                    Name = "susucake",
                    DisplayName = "susucake",
                    Description = "小蛋糕",
                    Type = "Cooking",
                    Category = StardewValley.Object.CookingCategory,
                    Price = 999999,
                    Texture = "susucake",
                    Edibility = 100
                };
                dict.Data["susucake"] = susucake;
                // hellokitty  
                var hellokitty = new ObjectData
                {
                    Name = "hellokitty",
                    DisplayName = "hellokitty",
                    Description = "不用小心对待我,请用心对待我就可以",
                    Type = "Furniture",
                    Price = 9999999,
                    Texture = "hellokitty"
                };
                dict.Data["hellokitty"] = hellokitty;
                // hellokitty  
                var dio = new ObjectData
                {
                    Name = "dio",
                    DisplayName = "dio",
                    Description = "星星点点装扮自己的梦",
                    Type = "Furniture",
                    Price = 9999999,
                    Texture = "dio"
                };
                dict.Data["dio"] = dio;
                
                
            });
        }

        //  加载物品贴图资源
        if (e.Name.IsEquivalentTo("susu"))
            e.LoadFromModFile<Texture2D>("assets/susu.png", AssetLoadPriority.Medium);

        if (e.Name.IsEquivalentTo("susucake"))
            e.LoadFromModFile<Texture2D>("assets/susucake.png", AssetLoadPriority.Medium);

        if (e.Name.IsEquivalentTo("hellokitty"))
            e.LoadFromModFile<Texture2D>("assets/hellokitty.png", AssetLoadPriority.Medium);

         if (e.Name.IsEquivalentTo("dio"))
            e.LoadFromModFile<Texture2D>("assets/dioman.png", AssetLoadPriority.Medium);

        //  烹饪配方：草莓 x1 + 小麦粉 x4 → susucake
        if (e.Name.IsEquivalentTo("Data/CookingRecipes"))
        {
            e.Edit(asset =>
            {
                var dict = asset.AsDictionary<string, string>();
                dict.Data["susucake"] = "400 10 246 4/1 10/susucake/default";

            });
        }

        //  合成配方：五彩碎片 x5 + 铱锭 x10 → susuheart
        if (e.Name.IsEquivalentTo("Data/CraftingRecipes"))
        {
            e.Edit(asset =>
            {
                var dict = asset.AsDictionary<string, string>();
                dict.Data["susuheart"] = "74 5 337 10/Field/susuheart/false";
            
            });
        }
    }

 
    private void OnSaveLoaded(object? sender, SaveLoadedEventArgs e)
    {
        // 授予合成配方
        if (!Game1.player.craftingRecipes.ContainsKey("susuheart"))
        {
            Game1.player.craftingRecipes.Add("susuheart", 0);
            Monitor.Log("已自动授予合成配方：susuheart", LogLevel.Info);
        }

        // 授予烹饪配方
        if (!Game1.player.cookingRecipes.ContainsKey("susucake"))
        {
            Game1.player.cookingRecipes.Add("susucake", 0);
            Monitor.Log("已自动授予烹饪配方：susucake", LogLevel.Info);
        }
    }
}
